using UnityEngine;

public class PoemSkill3Obj : Character
{
    private SkillData srcData;
    private Character target;

    public void Initialize(SkillData data,Character tar)
    {
        srcData = data.Clone();
        srcData.Source = null;
        srcData.DamageType = 2;

        transform.SetParent(LevelManager.Instance.transform);

        if (data.Source.teamType == TeamType.Player)
        {
            gameObject.layer = LayerMask.NameToLayer("Enemy");
            teamType = TeamType.Enemy;
        }
        else
        {
            gameObject.layer = LayerMask.NameToLayer("Player");
            teamType = TeamType.Player;
        }

        AddImmunity<Buff_Knockback>();

        target = tar;
        target.OnThisDeath += OnTargetDeath;
    }

    public override float TakeDamage(FinalDamageInfo info, bool canFeedback)
    {
        float delta = base.TakeDamage(info, canFeedback);

        FinalDamageInfo damageInfo = info.Clone();
        damageInfo.DamageType = 2;
        damageInfo.FinalDamage = delta;
        target.TakeDamage(damageInfo, false);

        return delta;
    }
    protected override void Death()
    {
        base.Death();
        Destroy(gameObject);
    }

    private void OnTargetDeath()
    {
        Destroy(gameObject);
    }
    private void OnDestroy()
    {
        if (target != null) target.OnThisDeath -= OnTargetDeath;
    }
}